PACKAGE = gitee.com/xuender/mysql-proxy
VERSION = $(shell git describe --tags)
BUILD_TIME = $(shell date +%FT%T)
GIT_COMMIT = $(shell expr substr `git log --pretty=format:'%H' -n 1` 1 7)
default: lint clean build go

lint:
	golangci-lint run

clean:
	rm -rf pb/*.pb.go
	rm -rf dist www

go: proto wire
	go build -ldflags \
  "-X '${PACKAGE}.Version=${VERSION}' \
  -X '${PACKAGE}.BuildTime=${BUILD_TIME}' \
	-X '${PACKAGE}.GitCommit=${GIT_COMMIT}'" \
  -o dist/proxy cmd/proxy/main.go

proto: protojs
	protoc --go_out=. \
	pb/*.proto
	# protoc --go_out=. --go-grpc_out=. pb/*.proto
	protoc-go-inject-tag -input=./pb/*.pb.go

protojs:
	./node_modules/.bin/pbjs -t static-module --force-number -w es6 --es6 -o src/pb.js ./pb/*.proto
	./node_modules/.bin/pbts -o src/pb.d.ts src/pb.js

wire:
	wire gen ${PACKAGE}/cmd

serve:
	ionic serve -- --proxy-config proxy.conf.json

build: protojs
	# sed -i "s/VERSION/${VERSION}/g" src/environments/environment.prod.ts
	# sed -i "s/BUILD_TIME/${BUILD_TIME}/g" src/environments/environment.prod.ts
	# sed -i "s/GIT_COMMIT/${GIT_COMMIT}/g" src/environments/environment.prod.ts
	node_modules/.bin/ionic build --prod --engine=browser --platform=android -- --base-href=./
	# git checkout src/environments/environment.prod.ts
